import { createSlice } from "@reduxjs/toolkit"


let slice=createSlice({
  name:'count',
  initialState:0,
  reducers:{
    add:(state,action)=>{
      return state+action.payload
    },
    sub:(state,action)=>{
      return state-action.payload
    }
  }
})
let reducer=slice.reducer

//同步
export let {add,sub}=slice.actions

//异步
export let asyncAdd=()=>{
  return dispatch=>{
    setTimeout(()=>{
      dispatch(add(10))
    },1000)
  }
}

export default reducer

